<?php

$oDb =& Database::get();
$oTpl =& App::getTemplate();
$oReq =& App::getRequest();

if ( $iDeleteId = $oReq->getInt('did') )
{
	$oDb->_delete(App::getT('chat_rooms'), "roomid = '". $iDeleteId ."'");
	App::gotoUrl('', array(), App::format('Mod_Shoutbox.delete.item'));
}

if ( ($iEditId = $oReq->getInt('eid')) && ($sText = $oReq->get('text')) )
{
	$oDb->update(App::getT('chat_rooms'), array('name' => strip_tags($sText)), "roomid = '". $iEditId ."'");
	App::gotoUrl('', array(), App::format('Mod_Chat.chat_room_updated'));
}

if ( ($sText = $oReq->get('new')) && !empty($sText) )
{
	$oDb->insert(App::getT('chat_rooms'), array('created' => time(), 'name' => strip_tags($sText), 'userid' => App::getUser('id')));
	App::gotoUrl('', array(), App::format('Mod_Chat.chat_room_created'));
}

$aRows = $oDb->getRows("
	SELECT c.roomid, c.name FROM
	". App::getT('chat_rooms') ." AS c
		LEFT JOIN ". App::getT('user') ." AS u ON(c.userid = u.id)
	ORDER BY c.name
");

$oTpl->assign(array
(
	'aRows' => $aRows
));

?>
